/*
* 2010
* Authors: Sergey Lapin <lapanoid@gmail.com>
* Realisation of numerator classes
*/
#include "../stdafx.h"

FasDirnumerator::FasDirnumerator(Graph *graph)
{
    worker = graph;
    Numeration();
}

FasInvnumerator::FasInvnumerator(Graph *graph)
{
    worker = graph;
    Numeration();
}


void FasDirnumerator::Numeration ()
{
    Vertex_Iterator vi, vend;
    Vertex_Number cnt_v = 0;    
    for (tie(vi,vend) = vertices(*worker); vi != vend; vi++, cnt_v++) {
        vertextable[*vi] = cnt_v;
    }
}


void FasInvnumerator::Numeration ()
{
    Vertex_Iterator vi, vend;
    Vertex_Number cnt_v = 0;    
    for (tie(vi,vend) = vertices(*worker); vi != vend; vi++, cnt_v++) {
        vertextable[cnt_v] = *vi;
    }
}

Vertex_Number FasDirnumerator::Map (Vertex in)
{
    Vertex2Int::iterator res;
    res = vertextable.find(in);
    return res->second;            
}

void FasDirnumerator::Map (list<Vertex> &in, list<Vertex_Number> *res)
{
    Vertex2Int::iterator tmp;
    for (list<Vertex>::const_iterator it = in.begin(); it != in.end(); ++it) {
        if ((tmp = vertextable.find(*it)) != vertextable.end()) {
            res->push_back(tmp->second);        
        }
    } 
}

Vertex FasInvnumerator::Map (Vertex_Number in)
{
    Int2Vertex::iterator res;
    res = vertextable.find(in);
    return res->second;        
}

void FasInvnumerator::Map (list<Vertex_Number> &in, list<Vertex> *res)
{
    Int2Vertex::iterator tmp;
    for (list<Vertex_Number>::const_iterator it = in.begin(); it != in.end(); ++it) {
        if ((tmp = vertextable.find(*it)) != vertextable.end()) {
            res->push_back(tmp->second);        
         }
    } 
}